package com.googlecode.astoolkit.modules.content.iterators {
	import com.googlecode.astoolkit.utils.INode;
	import com.googlecode.astoolkit.utils.NullNode;
	import com.googlecode.astoolkit.utils.Sitemap;
	


	public class ArrayIterator implements IIterator {
		
		private var _index:uint = 0;
		private var _collection:Array;
		
		public function ArrayIterator(collection:Array) {
			_collection = collection;
			_index = 0;
		}
		
		public function hasNext():Boolean {
			return _index < _collection.length && _collection.length > 0;
		}
		
		public function next():INode {
			// puede ser un int o undefined si el id es -1
			var n:* = _collection[_index++];
			return getNode(n);
		}
		
		public function current():INode {
			var n:* = _collection[_index];
			return getNode(n);
		}
		
		//
		private function getNode(n:*):INode{
			if(n==undefined){
				return new NullNode();
			}else{
				return Sitemap.getNodeById(n);
			}
		}
		
		public function reset():void {
			_index = 0;
		}
		
		
	}
}